package de.barny.worm;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.geom.RoundRectangle2D;

import de.barny.prefs.Var;

public class Apple {
	
	Color appleColor = new Color(255, 180, 170);
	
	public Apple() {
		
	}
	
	int posX;
	int posY;

	public void paint(Graphics gameFieldGraphics) {
		Graphics2D apple = (Graphics2D)gameFieldGraphics;
		apple.setColor(appleColor);
		apple.fill(getShape());
	}
	
	private Shape getShape() {
		int dotSize = Var.snakeDotSize;
		int roundness = Var.appleRoundness;
		RoundRectangle2D.Double shape = null;
		shape = new RoundRectangle2D.Double((posX-1)*dotSize, (posY-1)*dotSize, dotSize, dotSize, roundness, roundness);
		return shape;
	}
	
	public void setRandomPos() {
		int windowWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
		int windowHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
		int dotSize = Var.snakeDotSize;
		
		int possiblePosX = windowWidth/dotSize;
		int possiblePosY = windowHeight/dotSize;
		
		posX = (int) (Math.random()*possiblePosX);
		posY = (int) (Math.random()*possiblePosY);
		
		if ((posX == 0 && posY <= 0)) {
			posX = 1;
			posY = 1;
		} else if (posX == 0) {
			posX = 1;
		} else if (posY == 0) {
			posY = 1;
		}
	}
	
	public int getPosX() {
		return posX;
	}
	
	public int getPosY() {
		return posY;
	}
}
